import { FormConfig } from '@/components'
import { Row } from '@/components/FTable/components/search'
import { configCurryFilter } from '@/dictionaries/filter'
import { BaseDto } from '@/interfaces'
import dayjs from 'dayjs'
import { shallowRef } from 'vue'

/*
 * @Description: 
 * @Author: fhw
 * @Date: 2023-02-23 14:41:28
 */
import { last } from 'ramda'
export async function importFiles() {
	const files: any = import.meta.glob('/src/router/modules/*.ts')
	const modules: any[] = []
	for (const key in files) {
		const name = key.replace(/(\.\/modules\/|\.(js|ts))/g, "");
		const filename = last(name.split('/')) as string
		const res = await files[key]()
		Object.keys(res).forEach(item => {
			modules.push(res[item])
		})
	}
	return modules
}
export interface RoleState extends BaseDto {
	/** 角色名称 */
	rolename?: string
	/** 描述 */
	description?: string
	/** 启用状态 */
	status?: string
	/** 路由权限 */
	menu?: MenuState[]
}
export interface MenuState {
	/** 路由名称 */
	name?: string
	/** 路由地址 */
	path?: string
	/** 路由名称 */
	meta?: {
		/** 标题 */
		title?: string
		/** 是否隐藏 */
		alwaysShow?: string
	}
	/** 子路由 */
	children?: MenuState[]
}
export const columns: F.TableColumns[] = [
	{
		title: '角色名称',
		key: 'rolename',
		dataIndex: 'rolename',
		align: 'center',
	},
	{
		title: '描述',
		key: 'description',
		dataIndex: 'description',
		align: 'center',
		width: 200
	},
	{
		title: '启用状态',
		key: 'status',
		dataIndex: 'status',
		align: 'center',
		customRender: configCurryFilter('status')
	},
	{
		title: '创建时间',
		key: 'createDate',
		dataIndex: 'createDate',
		align: 'center',
		customRender: ({ record }: F.RableSlotScope<RoleState>) => dayjs(record.createDate).format('YYYY-MM-DD HH:mm:ss')
	},
	{
		title: '更新时间',
		key: 'updateDate',
		dataIndex: 'updateDate',
		align: 'center',
		customRender: ({ record }: F.RableSlotScope<RoleState>) => dayjs(record.updateDate).format('YYYY-MM-DD HH:mm:ss')
	},
	{
		title: '操作',
		dataIndex: 'action',
		key: 'action',
		align: 'center',
		slots: {
			customRender: 'actionRender',
		},
		width: 200,
		fixed: 'right',
	},
]
export const rows: Array<Row> = [
	{
		title: '角色名称',
		key: 'rolename',
		component: 'a-input',
	},
	{
		title: '启用状态',
		key: 'status',
		component: shallowRef(FormConfig),
		props: {
			prop: 'status'
		}
	},
	{
		title: '创建时间',
		key: 'createTimeStart',
		component: 'a-range-picker',
		props: {
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
		},
	},
	{
		title: '更新时间',
		key: 'updateTimeStart',
		component: 'a-range-picker',
		props: {
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
		},
	},
]